﻿<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<div id="createDialog" class="crudDialog">
    <form id="createForm" method="post">
        <input type="hidden" id="CSRFToken" name="CSRFToken" value="${CSRFToken}" />
        <div class="form-group">
            <label for="password">密码</label>
            <input id="password" type="text" class="form-control" name="password" maxlength="32">
        </div>
        <div class="form-group">
            <label for="confirmPassword">确认密码</label>
            <input id="confirmPassword" type="text" class="form-control" name="confirmPassword" maxlength="32">
        </div>

        <div class="form-group text-right dialog-buttons">
            <a class="waves-effect waves-button" href="javascript:;" onclick="createSubmit();">保存</a>
            <a class="waves-effect waves-button" href="javascript:;" onclick="createDialog.close();">取消</a>
        </div>
    </form>
</div>
<script>
    function createSubmit() {
        $.ajax({
            type: 'post',
            url: '${basePath}/manage/user/update/${userId}/password',
            data: $('#createForm').serialize(),
            beforeSend: function () {
                if ($('#password').val() == '' || $('#password').val().length < 5) {
                    $('#password').focus();
                    return false;
                }


                if ($('#confirmPassword').val() == '' || $('#confirmPassword').val().length < 5) {
                    $('#confirmPassword').focus();
                    return false;
                }


                if ($('#confirmPassword').val() != $('#password').val()) {
                    $('#confirmPassword').focus();
                    return false;
                }

            },
            success: function (result) {
                if (result.code != 1) {
                    $.confirm({
                        theme: 'dark',
                        animation: 'rotateX',
                        closeAnimation: 'rotateX',
                        title: false,
                        content: result.data.errorMsg || result.data,
                        buttons: {
                            confirm: {
                                text: '确认',
                                btnClass: 'waves-effect waves-button waves-light'
                            }
                        }
                    });
                } else {
                    changPasswordDialog.close();
                    $.confirm({
                        theme: 'dark',
                        animation: 'rotateX',
                        closeAnimation: 'rotateX',
                        title: false,
                        content: '更改成功！',
                        buttons: {
                            confirm: {
                                text: '确认',
                                btnClass: 'waves-effect waves-button waves-light'
                            }
                        }
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.confirm({
                    theme: 'dark',
                    animation: 'rotateX',
                    closeAnimation: 'rotateX',
                    title: false,
                    content: textStatus,
                    buttons: {
                        confirm: {
                            text: '确认',
                            btnClass: 'waves-effect waves-button waves-light'
                        }
                    }
                });
            }
        });
    }
</script>